import { combineReducers, configureStore } from "@reduxjs/toolkit";
import userReducer from './userSlice'
import { persistStore, persistReducer } from "redux-persist";
import  storage  from "redux-persist/lib/storage";


// 配置持久化对象
const persistConfig = {
    // 数据存储
    key:'persist',  // 自定义
    storage
}

const reducers = combineReducers({  // 所有的reducer合并为一个 
    user:userReducer
})
    // 持久化 reducer
    const persistedReducer = persistReducer(persistConfig,reducers)

const store = configureStore({
    reducer:persistedReducer,
    middleware:getDefaultMiddleware => getDefaultMiddleware({  //解决动作无法序列化的问题
        //关闭redux序列化检测
        serializableCheck:false
    })
})
// 持久化store
export const persistor = persistStore(store)

export default store